<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>2.属性的基本操作方法</title>
</head>
<body>
  <script>
    let user = {
      name: '向军',
      'my age': 18
    };
    //获得属性，可以用 . 和[]
    console.log(user.name); 
    console.log(typeof user); // object
    console.log(user['my age']); // 不合法变量名只能用[] 语法获得属性
    console.log(typeof user); // object
    // 遍历属性，获取value
    for(const key in user){
      console.log(user[key]);
    }
    //属性赋值
    user.age = 19;
    //增加属性
    user.get = function () {
      return `${this.name}的年龄是${this.age}`
    }
    console.log(user.get());//向军的年龄是19

    //删除属性
    delete user.age;
    console.log(user.get()); //向军的年龄是undefined
  </script>
</body>
</html>